package com.ruoyi.system.controller;


import java.util.List;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.system.domain.UserActiveCardRecord;
import com.ruoyi.system.service.IUserActiveCardRecordService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ActiveBoxConfig;
import com.ruoyi.system.service.IActiveBoxConfigService;
import com.ruoyi.common.core.page.TableDataInfo;


@RestController
@RequestMapping("/system/active")
public class ActiveController extends BaseController {

    @Autowired
    private IActiveBoxConfigService activeBoxConfigService;

    @Autowired
    private IUserActiveCardRecordService userActiveCardRecordService;

    /**
     * 查询【请填写功能名称】列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ActiveBoxConfig activeBoxConfig) {
        startPage();
        List<ActiveBoxConfig> list = activeBoxConfigService.selectActiveBoxConfigList(activeBoxConfig);
        return getDataTable(list);
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:active:box:add')")
    @Log(title = "【新增组组乐盒子】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ActiveBoxConfig activeBoxConfig) {
        return toAjax(activeBoxConfigService.insertActiveBoxConfig(activeBoxConfig));
    }

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(activeBoxConfigService.selectActiveBoxConfigById(id));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:active:box:edit')")
    @Log(title = "【修改组组乐盒子】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ActiveBoxConfig activeBoxConfig) {
        return toAjax(activeBoxConfigService.updateActiveBoxConfig(activeBoxConfig));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:active:box:del')")
    @Log(title = "【删除组组乐盒子】", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(activeBoxConfigService.deleteActiveBoxConfigByIds(ids));
    }

    /**
     * 复制盒子【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:active:box:copy')")
    @Log(title = "【复制组组乐盒子】", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/copy/{id}")
    public AjaxResult code(@PathVariable("id") Long id) {
        ActiveBoxConfig activeBoxConfig = activeBoxConfigService.selectActiveBoxConfigById(id);
        activeBoxConfig.setId(null);
        return toAjax(activeBoxConfigService.insertActiveBoxConfig(activeBoxConfig));
    }

    /**
     * 查询【玩家抽奖记录】列表
     */
    @GetMapping("/user/list")
    public TableDataInfo list(UserActiveCardRecord userActiveCardRecord) {
        startPage();
        List<UserActiveCardRecord> list = userActiveCardRecordService.selectUserActiveCardRecordList(userActiveCardRecord);
        return getDataTable(list);
    }

}
